package net.sdd.oss.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sdd.common.result.Result;
import net.sdd.oss.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/sddoss/file")
@Api(tags = "头像管理")
@CrossOrigin
public class FileController {

    @Autowired
    private IFileService fileService;

    /**
     * SpringBoot 中接收文件上传的参数使用MultipartFile；
     * 可以获取文件流、文件名称等。
     *
     */
    @PostMapping("/upload")
    @ApiOperation("头像上传")
    public Result uploadFile(@RequestPart MultipartFile file) {
        String url = fileService.uploadFile(file);
        return Result.ok().data("url",url);
    }
}